﻿/***************************************************************************************/
// Author                 - Balaji Venkatesan
// Student ID             - 12527079
// Version                - 1.0
// CodeName               - Northodyne Solutions
// Module                 - E-Business Technologies
// Date                   - 12-September-2011
/***************************************************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class CustomerSearchProperty : System.Web.UI.Page
{

    public string _connStr = "Initial Catalog=DBNorthodyneSolutions; Data Source=ABC\\SQLExpress;Trusted_Connection=Yes";
    public string _userName = string.Empty;

    protected void Page_Load(object sender, EventArgs e)
    {
        _userName = Session["UserName"].ToString();
        //lblUserName.Text = _userName;

        Label lblusername = (Label)Master.FindControl("lblUserName");
        HyperLink hyplogin = (HyperLink)Master.FindControl("hyplogin");
        lblusername.Text = _userName;
    }

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        using (SqlConnection connection = new SqlConnection(_connStr))
        {
            connection.Open();
            string selectPropertyInfo = "SELECT * from Tb_Property WHERE PropertyType = @PropertyType";

            using (SqlCommand selectCommand = new SqlCommand(selectPropertyInfo, connection))
            {

                SqlParameter[] proprms = new SqlParameter[1];
                proprms[0] = new SqlParameter("@PropertyType", SqlDbType.NVarChar, 50);
                proprms[0].SqlValue = ddlPropertyType.SelectedItem.Text.Trim();

                selectCommand.Parameters.AddRange(proprms);
                selectCommand.ExecuteNonQuery();

                SqlDataReader propertyReader = selectCommand.ExecuteReader();

                gvProperty.DataSource = propertyReader;
                gvProperty.DataBind();

                foreach (GridViewRow gvr in gvProperty.Rows)
                {
                    gvProperty.HeaderRow.Cells[1].Visible = false;
                    gvr.Cells[1].Visible = false;
                    gvProperty.HeaderRow.Cells[10].Visible = false;
                    gvr.Cells[10].Visible = false;
                    gvProperty.HeaderRow.Cells[11].Visible = false;
                    gvr.Cells[11].Visible = false;
                    gvProperty.HeaderRow.Cells[17].Visible = false;
                    gvr.Cells[17].Visible = false;
                }
            }
            connection.Close();
        }
    }
}